package com.sc.study.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.study.client.GeneralClient;
import com.sc.study.entity.StudyVideo;
import com.sc.study.dao.StudyVideoMapper;
import com.sc.study.service.StudyVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 研究视频服务impl
 *
 * @author 徐赫阳
 * @date 2021/10/26
 */
@Service
@Component
public class StudyVideoServiceImpl  extends ServiceImpl<StudyVideoMapper, StudyVideo> implements StudyVideoService {

    @Autowired
    private StudyVideoMapper studyVideoMapper;
    @Autowired
    private GeneralClient generalClient;

    @Override
    public void deleteById(Integer id){
        StudyVideo video = studyVideoMapper.selectById(id);
        if(video != null){
            if(video.getType() == 2){
                generalClient.deleteFileById(id);
            }
            studyVideoMapper.deleteById(id);
        }
    }

    @Override
    public List<StudyVideo> getVideoByHot(){
        return studyVideoMapper.selectVideoByHot();
    }

}
